<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../../../../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8"/>
    <title>代理商余额记录表</title>
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css"/>
    <style>
        button.searching{
            background-color:#666
        }
    </style>
</head>
<body>
 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		<div class="box-header">
	                 <h3 class="box-title">余额</h3>
	             </div>
	             <div class="box-header">
	                 <h3 id="money" class="box-title"></h3><h4>元</h4>
	             </div>
	             <div class="box-header">
	             	<table style="line-height:45px;font-size:14px;">
						<tr>
							<td>&nbsp;&nbsp;&nbsp;代理商名称：</td>
							<td><span style="line-height: 47px">${userBalanceVo.userName}</span></td>
						</tr>
					</table>
	             </div>
		 	</div>
		 </div>
	</div>
<div class="widget-box">
	<div class="widget-title">
	   <h5>请输入查询条件</h5>
	</div>
	<div class="widget-content nopadding">
		<table style="line-height:45px;font-size:12px;">
			<tr>
<!-- 				<td>&nbsp;&nbsp;&nbsp;代理商名称：</td> -->
<%-- 				<td><span style="line-height: 47px">${userBalanceVo.userName}</span></td> --%>
				<td>&nbsp;&nbsp;&nbsp;来源：</td>
				<td>
					<select class="form-control" name="transCode" id="transCode">
					  <option  selected="selected" value="-1">请选择</option>  
				      <option value ="1011">充值</option>  
				      <option value ="1014">提现</option> 
				      <option value="1006">供应链订单</option>  
				    </select>  
				</td>
				<td>&nbsp;&nbsp;&nbsp;时间：</td>
				<td>
					<input name="startTime" id="startTime" class="form-control" data-type="date_00" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"/>
				</td>
				<td>&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</td>
				<td>
					<input name="endTime" id="endTime" class="form-control" data-type="date_00" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"/>
				</td>
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success" href="javascript:void(0);" onclick="query();">查 询</a>
				</td>
                <td>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success" href="${ctx}/api/agent/chargeAgentPage?manageId=${userBalanceVo.manageId}">充 值</a>
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success" href="${ctx}/api/agent/drawcashAgentPage?manageId=${userBalanceVo.manageId}">提现申请</a>
                </td>
			</tr>
		</table>
	</div>
</div>
 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		<div class="box-header">
	                 <h3 class="box-title">代理商余额记录表</h3>
	             </div>
	             <!-- 列表 -->
	             <div class="box-body table-responsive">
	             	<table id="dataTablesBalance" class="table table-bordered table-hover">
	             	</table>
	             </div>
		 	</div>
		 </div>
	</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/time/WdatePicker.js" type="text/javascript"></script>
<script>
   var tb;
   $(function () {

		//禁止掉Ajaz的缓存机制
		$.ajaxSetup({ cache: false }); 
		var total  =  Math.floor((${userBalanceVo.balance}/10000)*100)/100;  
		$("#money").html(total);
		//列表初始化
		tb = $('#dataTablesBalance').dataTable({
				"bServerSide": true,
				"sPaginationType": "full_numbers",
				"bJQueryUI": true,
				"sDom": '<"">t<"F"ip>',
				"sAjaxSource": "${ctx}/api/agent/agentBalanceList", //ajax调用接口
				"aoColumnDefs": [{sDefaultContent: '',aTargets: [ '_all' ]}],
	       		"aoColumns": [
					  	{ "sTitle" : "编号", 	 "mData": "id" ,"class":"sClass"},
		                { "sTitle" : "代理商名称","mData": "name","class":"sClass" },
		                { "sTitle" : "来源","mData": "transCode","class":"sClass" ,"mRender":function(data, type, full){
		                	var text;
	                    	if(full.transCode=='1011'){
	                    		text="<font>充值</font>";
	                    	}else if(full.transCode=='1006'){
	                    		text="<font>供应链订单</font>"
	                    	}else if(full.transCode=='1014'){
	                    		text="<font>提现</font>"
	                    	}else{
		                    	text=full.supplierType;
	                    	}
	                    	return text;
	        				}
		                },
		                { "sTitle" : "订单号","mData": "orderNo","class":"sClass" },
		                { "sTitle" : "时间","mData": "createTime","class":"sClass","mRender":function(data, type, full){
		                	if((full.createTime) == 'null' || (full.createTime) == ""){
		                		return "";
		                	}else{
		                		return (full.createTime).substring(0,(full.createTime).length-2);
		                	}
		                }
		                },
		                { "sTitle" : "金额","mData": "money","class":"sClass" },
		                { "sTitle" : "备注","mData": "remark","class":"sClass" },
	            ],
		        "oLanguage" : {
		           "sProcessing" : "数据加载中······",
		           "sLengthMenu" : "显示 _MENU_ 条记录",
		           "sZeroRecords" : "没有您要搜索的内容！",
		           "sEmptyTable" : "列表中无数据存在！",
		           "sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
		           "sInfoEmpty" : "显示 0 到 0 条记录",
		           "sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
		           "oPaginate" : {
		               "sFirst" : "首页",
		               "sPrevious" : "上一页",
		               "sNext" : "下一页",
		               "sLast" : "末页"
		           }
		        },
		        "fnServerData" : function ( sSource, aoData, fnCallback, oSettings ) {
					oSettings.jqXHR = $.ajax( {
						"dataType" 	: 'json',
						"type" 		: "GET",
						"async"     : 'false',
						"url" 		: sSource,
						"data" 		: {
							'pageNum': (aoData[3].value/aoData[4].value)+1,
							'pageSize' :  aoData[4].value,
							'transCode'  :  $("#transCode").val(),
							'userId'  :  ${userBalanceVo.manageId},
							'name'  :  $("#name").val(),
							'startTime'  :  $("#startTime").val(),
							'endTime'  :  $("#endTime").val(),
						}, 
						"success"	: fnCallback
					} );
				},
		  });
   });
   
   //条件查询重新加载数据
   function query() {


	  //禁止掉Ajaz的缓存机制
	  $.ajaxSetup({ cache: false }); 
	  var startTime = $("#startTime").val();
	  var endTime = $("#endTime").val();
	  if(startTime!=""&&endTime!=""&&!compareDate(startTime,endTime)){
		  alert("查询条件开始时间不能大于结束时间!");
		  return;
	  }
 	  tb.fnDraw();
   };
   
   
   //时间比较
   function compareDate(DateOne, DateTwo) {
	   var OneMonth = DateOne.substring(5, DateOne.lastIndexOf("-"));
	   var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf("-") + 1);
	   var OneYear = DateOne.substring(0, DateOne.indexOf("-"));
	   var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf("-"));
	   var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf("-") + 1);
	   var TwoYear = DateTwo.substring(0, DateTwo.indexOf("-"));
	   if (Date.parse(OneMonth + "/" + OneDay + "/" + OneYear) <= Date.parse(TwoMonth + "/" + TwoDay + "/" + TwoYear)) {
	     return true;
	   } else {
	     return false;
	   }
	 }
</script>
</body>
</html>